# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=obs-studio
pkgver=30.2.3
pkgrel=0
pkgdesc="Free and open source software for live streaming and screen recording"
url="https://obsproject.com/"
arch="all !ppc64le !riscv64 !loongarch64" # luajit
license="GPL-2.0-or-later"
options="!check"
makedepends="
	alsa-lib-dev
	appstream-glib
	cmake
	curl-dev
	eudev-dev
	fdk-aac-dev
	ffmpeg-dev
	ffnvcodec-headers
	fontconfig-dev
	freetype-dev
	jack-dev
	jansson-dev
	librist-dev
	libdatachannel-dev
	libsrt-dev
	libva-glx-dev
	libva-dev
	libxcb-dev
	libx11-dev
	libxcomposite-dev
	libxinerama-dev
	libxkbcommon-dev
	luajit-dev
	mesa-dev
	nlohmann-json
	openssl-dev
	pciutils-dev
	pipewire-dev
	pulseaudio-dev
	python3-dev
	py3-glad
	qt6-qtbase-dev
	qt6-qtsvg-dev
	samurai
	sed
	sndio-dev
	speexdsp-dev
	swig
	uthash-dev
	v4l-utils-dev
	wayland-dev
	x264-dev
	"
subpackages="$pkgname-dev"
source="https://github.com/obsproject/obs-studio/archive/$pkgver/obs-studio-$pkgver.tar.gz
fix-cmake-settings.patch"

# armhf, s390x have no vlc
case $CARCH in
	armhf|s390x)
		_vlc=OFF
		;;
	*)
		makedepends="$makedepends vlc-dev"
		_vlc=ON
		;;
esac

# Regression for VPL only available for x86_64
# https://github.com/obsproject/obs-studio/issues/9578
case $CARCH in
	x86_64)
		makedepends="$makedepends onevpl-dev"
		_vpl=ON
	;;
	*)
		_vpl=OFF
	;;
esac

prepare() {
	default_prepare
	# no toggle for these, but the dirs are empty by default
	# make them valid cmake subdirs that do nothing
	touch plugins/obs-browser/CMakeLists.txt
	touch plugins/obs-websocket/CMakeLists.txt
	rm -rf deps/glad/include/EGL
	rm -rf deps/glad/include/KHR
}

build() {
	export CFLAGS="$CFLAGS  -Wno-incompatible-pointer-types"
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DOS_POSIX=ON \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DOBS_VERSION_OVERRIDE=$pkgver \
		-DCALM_DEPRECATION=ON \
		-DOPENGL_opengl_LIBRARY=/usr/lib/libGL.so \
		-DENABLE_AJA=OFF \
		-DENABLE_LIBFDK=ON \
		-DENABLE_JACK=ON \
		-DENABLE_WEBRTC=ON \
		-DOpenGL_GL_PREFERENCE=GLVND \
		-DCALM_DEPRECATION=ON \
		-DENABLE_VST=ON \
		-DUNIX_STRUCTURE=1 \
		-DENABLE_QSV11=$_vpl \
		-DENABLE_VLC=$_vlc \
		-Wno-dev
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
1fea762b8fb4d5401516d9e547fe20db389633fb1abbdb52e4b9559ab6aaf3b9f4c25e055896b4063c6a693bfeb78e6463486b4c66e3994a6d1ceb0b7f65865f  obs-studio-30.2.3.tar.gz
53df69665646f95d653c8ef39358c4d7473236cd03b2fe30b6ccf46461f1ef6065a945501dd32c798bf897d4b5d9675e98df6840132c903ee41051eb5bf43987  fix-cmake-settings.patch
"
